#ifndef __FRAGMENT_LINKLAYER_H__
#define __FRAGMENT_LINKLAYER_H__


#define LINKLAYER_VERSION "1.0.0"

#include "stdint.h"

#define FRAME_HEADER_H      (0xAA)
#define FRAME_HEADER_L      (0x55)
#define FRAME_HEADER        ((FRAME_HEADER_H << 8) | FRAME_HEADER_L)
#define FRAME_TAIL_H        (0x0D)
#define FRAME_TAIL_L        (0x0A)
#define FRAME_TAIL          ((FRAME_TAIL_H << 8) | FRAME_TAIL_L)

#ifndef NULL
    #define NULL (void*)(0)
#endif


#define MAX_FRAME_LEN       (32)
#define MIN_FRAME_LENGTH    (10)     // 10 = 2 (header) + 2 (length) + 2 (frame_id) + 2 (checksum) + 2 (tail)
#define FRAME_PAYLOAD_LEN   (MAX_FRAME_LEN - MIN_FRAME_LENGTH)
typedef struct FrameBuff
{
    uint8_t arrData[MAX_FRAME_LEN];
    uint16_t length;
} FrameBuff_t;


typedef enum 
{
    LINK_SUCCESS = 0x00,
    LINK_ERR_FRAME = 0xE1,
    LINK_ERR_FRAME_PARAM,
    LINK_ERR_FRAME_HEAD,
    LINK_ERR_FRAME_TAIL,
    LINK_ERR_SUMCHECK,
    LINK_ERR_FRAME_LENGTH,
    LINK_ERR_REPEAT,
} Fragment_LinkError_e;


Fragment_LinkError_e Fragment_Frame_Parse(const uint8_t* in_data, uint16_t in_len, FrameBuff_t* out_payload) ;
uint16_t Fragment_Frame_Serialize(FrameBuff_t *in_payload, uint8_t *output, uint16_t buf_size);


#endif // __FRAGMENT_LINKLAYER_H__